package com.gpj.learn.rabbitmq.springboot.system;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.TopicExchange;

/**
 * @className RabbitMQConfiguration
 * @description RabbitMQ业务配置信息类
 * @author GPJ
 * @date 2021/9/3 16:21
 * @version 1.0
 **/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class RabbitMQProperty {
	// 队列名
	private String queue;

	// 模式类型 null-工作模式;routing-路由模式;topic-主题模式;fanout-广播模式
	private String type;

	// 交换机名称,工作模式不需要配置
	private String exchange;

	// 路由key,工作模式不需要配置
	private String routingKey;

	public Class<? extends Exchange> generateExchangeClass() {
		switch (type) {
			case "routing":
				return DirectExchange.class;
			case "topic":
				return TopicExchange.class;
			case "fanout":
				return FanoutExchange.class;
			default:
				throw new RuntimeException("未知的MQ模式,请检查MQ相关配置是否正确 ->"
						+ "{queue:" + queue + ", type:" + type + ", "
						+ "exchange:" + exchange + ", routingKey:" + routingKey + "}");
		}
	}
}
